//
// Created by benxb on 2021/12/7.
//

#ifndef BENXDB_POINT_CLOUD_H
#define BENXDB_POINT_CLOUD_H

#include <initializer_list>
#include <vector>
#include <memory>

namespace benxdb {

template<typename PointT>
class PointCloud {
public:
    typedef typename std::vector<PointT>::size_type size_type;

    PointCloud() {
        data_ = std::shared_ptr<std::vector<PointT>>(new std::vector<PointT>());
    }

    explicit PointCloud(int size) {
        data_ = std::shared_ptr<std::vector<PointT>>(new std::vector<PointT>(size));
    }

    PointT& operator[](size_t index) {
        return data_->at(index);
    }

    PointCloud(std::initializer_list<PointT> il);

    ~PointCloud() = default;

    size_type Size() const {
        return data_->size();
    }

    bool Empty() const {
        return data_->empty();
    }

    void Append(const PointT &point) {
        data_->push_back(point);
    }

    void Append(PointT &&point) {
        data_->push_back(point);
    }

    std::shared_ptr<std::vector<PointT>> AllPoints() {
        return data_;
    }

    void Clear() {
        data_->clear();
    }

private:
    std::shared_ptr<std::vector<PointT>> data_;
};

}

#endif //BENXDB_POINT_CLOUD_H
